<template>
    <div class="new-wrap">
        <div class="new-content">
            <div class="new-box">
                <div class="new-left"></div>
                <div class="new-right">
                    <div class="new-from">
                        <el-form
                            ref="ruleForm"
                            :model="ruleForm"
                            :rules="rules"
                            label-width="0px"
                        >
                            <el-form-item
                                prop="username"
                                class="new-user"
                            >
                                <img
                                    src="../assets/image/logo-user.png"
                                    alt=""
                                />
                                <el-input
                                    v-model="ruleForm.username"
                                    autocomplete="off"
                                    placeholder="请输入用户名"
                                ></el-input>
                            </el-form-item>
                            <el-form-item
                                prop="password"
                                class="new-pwd"
                            >
                                <img
                                    src="../assets/image/logo-pwd.png"
                                    alt=""
                                />
                                <el-input
                                    v-model="ruleForm.password"
                                    class="new-pwd"
                                    style="margin-top: 10px;"
                                    type="password"
                                    placeholder="请输入密码"
                                    autocomplete="off"
                                    @keyup.enter.native="submitForm('ruleForm')"
                                ></el-input>
                            </el-form-item>
                            <el-form-item
                                v-if="vercode"
                                prop="code"
                            >
                                <img
                                    src="../assets/image/m3.png"
                                    alt=""
                                    class="code"
                                />
                                <el-input
                                    v-model.trim="ruleForm.code"
                                    placeholder="请输入验证码"
                                    style="width:60%"
                                    class="check-code"
                                ></el-input>
                                <img
                                    :src="imageCodeSrc"
                                    alt=""
                                    class="code-image"
                                    @click="getUid"
                                >
                            </el-form-item>
                        </el-form>
                    </div>
                    <div
                        class="login-btn"
                        @click="submitForm('ruleForm')"
                    ></div>
                </div>
            </div>
            <div class="new-abs">
                <div class="new-line1">
                    <img
                        src="../assets/image/logo-yuan1.png"
                        alt=""
                    />
                </div>
                <div class="new-line2">
                    欢迎使用
                </div>

                <div class="new-line4">
                    统一数据接入
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import Cookie from 'js-cookie'

export default {
    data() {
        return {
            ruleForm: {
                username: '',
                password: '',
                code: '',
            },
            rules: {
                username: [
                    { required: true, message: '请输入用户名', trigger: 'blur' },
                ],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
                code: [{
                    required: true,
                    message: '请输入验证码',
                    trigger: 'blur',
                }],
            },
            cacheUuidKey: '',
            imageCodeSrc: '',
            vercode: false,
        };
    },
    computed: {
        // loginTitle() {
        //     return window.pageData.login.loginTitle;
        // },
        // footerCopyRightText() {
        //     return window.pageData.login.footerCopyRightText;
        // },
    },
    mounted() {
        this.getUid()
    },
    methods: {
        async getUid() {
            const res = await this.$api.login.getUid()
            console.log(res)
            if (res.data.resultCode === 0) {
                this.cacheUuidKey = res.data.resultMessage
                this.imageCodeSrc = `${window.conf.domain2}/auth/v1/login-verification/get-verification-code?uuidKey=${res.data.resultMessage}`;
            }
        },
        async submitForm(formName) {
            try {
                const valid = await this.$refs[formName].validate();

                await this._loginSync();
            } catch (error) {
                // this.$message.error(error);
            }
        },
        async _loginSync() {
            const options = {
                // appCode: 'TYMHGLXT',
                cacheUuidKey: this.cacheUuidKey,
                username: this.ruleForm.username,
                password: this.ruleForm.password,
                verifyFlag: this.vercode,
                verifycationCode: this.ruleForm.code,
            };

            const res = await this.$api.login.login(options);
            if (res.data.resultCode === 0) {
                Cookie.set('token', res.data.data.token)
                const str = JSON.stringify(res.data.data)

                localStorage.setItem('loginToken', res.data.data.token)
                this.$emit('hasToken', true)
                this.$router.replace({ path: '/home' });
            } else {
                this.vercode = true
                this.getUid()
                this.$message({ message: res.data.resultMessage, type: 'error' })
            }
        },
    },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.new-wrap {
  display: flex;
  justify-content: center;
  align-items: Center;
  height: 100%;
  background: #f8f9fb;
}
.new-foot {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  text-align: center;
  font-weight: 400;
  color: rgba(100, 99, 99, 1);
  font-size: 12px;
  line-height: 36px;
}
.new-fix {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 200px;
  height: 200px;
}
.new-box {
  width: 960px;
  margin: 0 auto;
  display: flex;
  margin-top: 320px;
  position: relative;
  .new-left {
    background: #1e212c;
    width: 480px;
    height: 200px;
  }
  .new-right {
    background: #fff;
    width: 480px;
    height: 200px;
    display: flex;
    position: relative;
    .new-from {
      padding-left: 50px;
      width: 350px;
      display: flex;
      align-items: center;
      .el-form {
        width: 85%;
      }
      .el-form-item {
        position: relative;
        margin-bottom: 12px;
        img {
          position: absolute;
          top: 5px;
          left: 0;
          width: 20px;
          z-index: 2;
        }
        .code{
          width: 18px;
        }
        .code-image{
            height: 35px;
            border-radius: 10px;
            margin-left: 20px;
            cursor: pointer;
            vertical-align: bottom;
            width: 80px;
            position: static;
        }
        /deep/.el-input__inner {
          padding-left: 30px;
        }
      }
      .new-pwd {
        img {
          top: 21px;
        }
      }
    }
    .login-btn {
      cursor: pointer;
      width: 92px;
      height: 42px;
      background: url("../assets/image/logo-btn.png") no-repeat center right;
      background-size: 92px 42px;
      position: absolute;
      bottom: 58px;
      right: 20px;
    }
  }
}
/deep/ .el-input__inner {
  border: none;
  height: 36px;
  line-height: 36px;
  border-bottom: 1px solid #c9cdd0;
}
.new-abs {
  position: absolute;
  width: auto;
  top: 278px;
  left: 170px;
  img {
    display: block;
    width: 100%;
  }
  .new-line1 {
    width: 70px;
    height: 70px;
    margin-bottom: 30px;
  }
  .new-line2 {
    color: #e0e0e0;
    font-size: 26px;
    font-weight: 400;
    margin-bottom: 10px;
  }
  .new-line3 {
    width: 76px;
    // height: 19px;
    margin-bottom: 10px;
  }
  .new-line4 {
    color: #e0e0e0;
    font-size: 20px;
    font-weight: 800;
  }
}
.new-content {
  position: relative;
  width: 1200px;
  height: 500px;
  background: url("../assets/image/logo-bg.png") no-repeat center right;
  background-size: 1200px 440px;
}
.login-wrap {
  position: fixed;
  height: 100%;
  width: 100%;
  z-index: 2;
  background: url("../assets/image/back-ground1.png") no-repeat center right;
  background-size: auto;
}
.login-warp-bg {
  position: fixed;
  height: 100%;
  width: 100%;
  z-index: 1;
  background-image: linear-gradient(to right, #095cfe 27%, #0ebcfb 98%);
}
.login-login {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  min-width: 800px;
}

.login-login .main {
  position: relative;
  top: 0;
  left: 0;
  width: 100%;
  height: calc(100% - 66px);
  min-height: 400px;
}
.login-icon {
  width: 353px;
  height: 50px;
  border-radius: 4px;
  margin-top: 119px;
}
.login-form {
  position: absolute;
  top: 50%;
  width: 353px;
  right: 387px;
  text-align: center;
  transform: translate(0, -53%);
  height: 62%;
}

.login-form .title {
  font-size: 40px;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 10px;
}

.login-form .subtitle {
  color: #ffffff;
  font-size: 22px;
  font-weight: 300;
}

.login-form .login-btn {
  background-color: #ffffff;
  color: #018aff;
  font-size: 20px;
  height: 50px;
  line-height: 50px;
  border-radius: 30px;
  margin-top: 145px;
  cursor: pointer;
}
.admin-link {
  color: transparent;
  display: inline-block;
  height: 50px;
  width: 100px;
  cursor: pointer;
  float: right;
}
</style>

<style>
.login-form .login-icon .el-input__inner {
  height: 50px !important;
  font-size: 16px;
  border-radius: 4px;
  opacity: 1;
}
input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0px 1000px rgba(255, 255, 255) inset;
}

</style>
